#include "HintDialog.h"
#include "ui_HintDialog.h"
#include "Mcu.h"

HintDialog *HintDialog::getInstance()
{
    static HintDialog singleton{};
    return &singleton;
}

HintDialog::HintDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::HintDialog)
{
    ui->setupUi(this);

#ifdef arm
    move(340, 250);
#else
    move((1920 - 600)/2, (1080 - 250)/2);
#endif
}

void HintDialog::setInfo(QString info, HintDialogType type)
{
    g_type = type;
    ui->info->setText(info);
}

HintDialog::~HintDialog()
{
    delete ui;
}

void HintDialog::showEvent(QShowEvent *)
{
    switch (g_type) {
    case HintDialogType_Null:
    case HintDialogType_Hint:
    case ModifyPatientUi_Modify:
        ui->no->hide();
        break;

    case PatientInfoUi_Delete:
    case ModifyPatientUi_GoHome:
    case ModifyPatientUi_GoBack:
    case ModifyPatientUi_Apply:
    case McuWorker_SystemShutdown:
    case SystemSettingUi_QuitLogoin:
        ui->no->show();
        break;
    }
}

void HintDialog::changeEvent(QEvent *e) {
    QWidget::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void HintDialog::on_no_clicked()
{
    Mcu::getInstance()->touchSoundBeepMessage();
    hide();
}

void HintDialog::on_ok_clicked()
{
    switch (g_type) {
    case ModifyPatientUi_Modify:
    case ModifyPatientUi_GoHome:
    case ModifyPatientUi_GoBack:
    case ModifyPatientUi_Apply:
        Mcu::getInstance()->touchSoundBeepMessage();
        emit ModifyPatientUi_HintDialog_Signal(g_type);
        break;

    case PatientInfoUi_Delete:
        Mcu::getInstance()->touchSoundBeepMessage();
        emit PatientInfoUi_HintDialog_Signal(g_type);
        break;

    case McuWorker_SystemShutdown:
        system("sync");
        emit McuWorker_SystemShutdown_Signal();
        break;

    case SystemSettingUi_QuitLogoin:
        Mcu::getInstance()->touchSoundBeepMessage();
        emit SystemSettingUi_QuitLogoin_Signal();
        break;

    default:
        break;
    }
    hide();
}
